﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace QuanLyDiemHocSinh
{
    public partial class Xoa_Tai_Khoan : System.Web.UI.Page
    {
        String tendn;
        
        protected void Page_Load(object sender, EventArgs e)
        {
            string chuoiketnoi = "Server=.\\SqlExpress;Integrated Security=True;Database=QuanLyDiem";
            SqlConnection ketnoi = new SqlConnection(chuoiketnoi);
            SqlDataReader rdr = null;
            SqlCommand cmd = new SqlCommand("select MaNguoiDung from NguoiDung", ketnoi);
            try
            {
                ketnoi.Open();

                rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    tendn = (string)rdr["MaNguoiDung"];
                    ListItem item = new ListItem(tendn, tendn);
                    ddTendn.Items.Add(item);
                }
            }
            catch (Exception ex)
            {
                lbthongbao.Text = ex.ToString();
            }
           
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string chuoiketnoi = "Server=.\\SqlExpress;Integrated Security=True;Database=QuanLyDiem";
            SqlConnection ketnoi = new SqlConnection(chuoiketnoi);
            SqlCommand cmd = new SqlCommand("delete from NguoiDung where (MaNguoiDung=@tentk)", ketnoi);
            cmd.Parameters.AddWithValue("@tentk", ddTendn.Text);
            
            try
            {
                ketnoi.Open();
                cmd.ExecuteNonQuery();
                lbthongbao.Text = "Xóa tài khoản thành công!";
            }
            catch (Exception exx)
            {
                lbthongbao.Text = exx.ToString();
            }
        }
    }
}